package com.jsptpd.smartauth.common.util;

import com.jsptpd.smartauth.modules.business.utils.Constants;

import javax.servlet.http.HttpServletRequest;

public class AppAuthUtils {
    /**
     * 校验appId和appKey
     */
    public static boolean checkAppIdAndKey(HttpServletRequest httpServletRequest) {
        String appId = getAppId(httpServletRequest);
        String appKey = getAppKey(httpServletRequest);
        if (appId == null || appId.isEmpty() || appKey == null || appKey.isEmpty()) {
            return false;
        } else if (Constants.APP_GROUP.get(appId) != null && Constants.APP_GROUP.get(appId).equals(appKey)) {
            return true;
        } else {
            return false;
        }
    }

    public static String getAppId(HttpServletRequest httpServletRequest){
        return httpServletRequest.getHeader(Constants.AUTH_HEADTAG_APPID);
    }

    public static String getAppKey(HttpServletRequest httpServletRequest){
        return httpServletRequest.getHeader(Constants.AUTH_HEADTAG_APPKEY);
    }

}
